package com.designpatterns.visitorpattern.impl;

import com.designpatterns.visitorpattern.ComputerPart;
import com.designpatterns.visitorpattern.ComputerPartVisitor;

public class Computer implements ComputerPart
{

	ComputerPart[] parts;

	public Computer()
	{
		parts = new ComputerPart[]
		{ new Mouse(), new Keyboard(), new Monitor() };
	}

	// 从程序运行结果来看，computerPartVisitor指向ComputerPartDisplayVisitor
	@Override
	public void accept(ComputerPartVisitor computerPartVisitor)
	{
		// 电脑里面的多个零件供访问者访问
		// 访问者访问多个零件
		for (int i = 0; i < parts.length; i++)
		{
			parts[i].accept(computerPartVisitor);
		}

		// 访问者访问当前类：电脑
		computerPartVisitor.visit(this);
	}
}
